<?php
namespace Home\Controller;
use Home\Controller;
/**
* 文章管理
*/
class MsgController extends AdminController
{
	/**
	 * 留言管理
	 * @return [type] [description]
	 */
	public function listMsg($order = 'id')
	{
		$admininfo = $this->checkLogin();
		$this->assign('admininfo', $admininfo);

		$msg = M('Msg');
		$res = $msg->field('id,name,email,msg,time')->order($order)->select();
		$this->assign('res', $res);
		$this->display();
	}
	/**
	 * 添加留言
	 */
	public function addMsg()
	{
		$comment = D('Comment');
		if (!$comment->create()) {
			alertMes($comment->getError());
		} else {
			$arr['name'] = I('post.name');
			$arr['email'] = I('post.email');
			$arr['msg'] = I('post.comment');
			$arr['time'] = time();
			$msg = M('Msg');
			$res = $msg->add($arr);
			if ($res) {
				alertMes('留言成功');
			} else {
				alertMes('留言失败');
			}
		}
	}
	/**
	 * 删除留言
	 * @param  int $id [description]
	 * @return [type]     [description]
	 */
	public function delMsg($id)
	{
		$msg = D('msg');
		$res = $msg->where('id=' . $id)->delete();
		if ($res) {
			alertMes('删除成功', U('msg/listMsg'));
		} else {
			alertMes('删除失败', U('msg/listMsg'));
		}
	}
	/**
	 * 回复邮件
	 * @return [type] [description]
	 */
	public function email()
	{
		$name = I('post.name');
		$email = I('post.email');
		$content = I('post.content');
		if (sendEmail($name, $email, $content)) {
			alertMes('邮件发送成功');
		} else {
			alertMes('邮件发送失败');
		}
	}
}